import processing.core.PImage;

public class SongsArea extends GuiElement {
	
	TagCloud tagCloud;
	// Text box used to select Songs
	TextBoxSong textBoxSong;
	
	// Selected songs Area
	SongsSelected songsSelected;

	PImage tick,no_tick;
	
	public SongsArea(float x, float y, float w, float h) {
		this.x = x;
		this.y = y;
		width = w;
		height = h;

		textBoxSong = new TextBoxSong("Search Song...");

		textBoxSong.x = 50;//60;
		textBoxSong.y = 80;
		
		songsSelected = new SongsSelected(50+190+30, 80, 810, 150); //x=250
		
		tick = GLOBAL.processing.loadImage("tick.png");
		no_tick = GLOBAL.processing.loadImage("close.png");
		
	} 
	
	public void draw() {
		
		if (tagCloud != null)
			tagCloud.draw();
		
		songsSelected.draw();
		textBoxSong.draw();
	}
	
	public void mousePressed() {
		if(textBoxSong.scrollBar.mouseOver()){textBoxSong.scrollBar.mousePressed();}
		else if(textBoxSong.mouseOver()){
			if(!textBoxSong.active){textBoxSong.active=true;}
			else{textBoxSong.active=false;}
		}	
		else if(songsSelected.verticalScrollBar.mouseOver())songsSelected.verticalScrollBar.mousePressed();
		else songsSelected.mousePressed();
	}
	
	public boolean mouseOver(){
		if(textBoxSong.active && textBoxSong.mouseOverSuggestions()) return true;
		return super.mouseOver();

	}
	
	public void changeTagCloud() {
		String lyrics = "";
		for (int i=0; i<GLOBAL.songsSelected.size() ;i++)
			if (GLOBAL.songsSelected.get(i).lyrics_found)
				lyrics = lyrics + " " + GLOBAL.songsSelected.get(i).lyrics.toLowerCase();
		tagCloud = new TagCloud(lyrics, x+20, y+height/2 -100, GLOBAL.width-40, 380);
	}
	
	public void mouseReleased(){
		textBoxSong.scrollBar.mouseReleased();
		songsSelected.verticalScrollBar.mouseReleased();
	}
	
}
